package com.whh.controller;

import com.whh.service.ContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * @Auther:wanghao
 * @Date: 2022/7/13,22:49
 * @Desc:
 */
@Controller
public class ContentController {

    @Autowired
    private ContentService contentService;


    @GetMapping("/add/{keywords}")
    @ResponseBody
    public Boolean addContent(@PathVariable("keywords") String keywords) throws Exception {
      return   contentService.parseContent(keywords);
    }

    @GetMapping("/query/{keywords}/{pageNo}/{pageSize}")
    @ResponseBody
    public List<Map<String,Object>> queryContent(@PathVariable("keywords") String keywords,
                                                 @PathVariable("pageNo") int pageNo,
                                                 @PathVariable("pageSize") int pageSize) throws IOException {
      return   contentService.searchPage(keywords,pageNo,pageSize);
    }
    @GetMapping("/search/{keywords}/{pageNo}/{pageSize}")
    @ResponseBody
    public List<Map<String,Object>> queryHighlightSearch(@PathVariable("keywords") String keywords,
                                                 @PathVariable("pageNo") int pageNo,
                                                 @PathVariable("pageSize") int pageSize) throws IOException {
        return   contentService.highlightSearch(keywords,pageNo,pageSize);
    }
}
